package com.jungle.bfi.service.metadata.impl;

import com.jungle.base.domain.bo.BaseUserBo;
import com.jungle.base.service.AbstractService;
import com.jungle.bfi.dao.DataDefinitionRepository;
import com.jungle.bfi.domain.bo.DataDefinitionBo;
import com.jungle.bfi.domain.vo.DataDefinitionVo;
import com.jungle.bfi.entity.DataDefinitionPo;
import com.jungle.bfi.service.metadata.DataDefinitionService;
import jakarta.annotation.Resource;
import org.n3r.idworker.Sid;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataDefinitionServiceImpl extends AbstractService<DataDefinitionPo, DataDefinitionBo, String> implements DataDefinitionService {

    @Resource
    private DataDefinitionRepository dataDefinitionRepository;
    @Override
    protected String getBoId(DataDefinitionBo bo) {
        return bo.getId();
    }

    @Override
    protected String newPoId() {
        return Sid.next();
    }

    @Override
    protected DataDefinitionPo createPo(DataDefinitionBo bo, BaseUserBo userBo) {
        return mapper.map(bo, DataDefinitionPo.class);
    }

    @Override
    public List<DataDefinitionVo> scenarioList(DataDefinitionBo bo) {
        List<DataDefinitionPo> list = dataDefinitionRepository.scenarioList(bo);
        return list.stream().map(this::convert).toList();
    }

    public DataDefinitionVo convert(DataDefinitionPo po) {
        return mapper.map(po, DataDefinitionVo.class);
    }
}
